# ui/project_tree.py
import json
import os
import pandas as pd
from typing import Optional
from PyQt5.QtWidgets import (
    QDockWidget, QTreeWidget, QTreeWidgetItem, QMenu, QInputDialog,
    QMessageBox, QLineEdit, QHeaderView
)
from PyQt5.QtCore import Qt
import logging

#项目树
#1. 显示导入的txt文件的表头和表内容
#2. 点击导入后,左侧树状菜单栏(ProjectTreeDock)相应变化
#3.显示导入的文件名称(可重命名)和字段
#4. 点击导入后,右侧竖向可视化(VerticalVisualizationDock)相应变化


class ProjectTreeDock(QDockWidget):
    
    dock_area=Qt.LeftDockWidgetArea

    def __init__(self,parent=None):
        super().__init__(parent)
        # 设置允许浮动和停靠
        self.setAllowedAreas(
            Qt.LeftDockWidgetArea |
            Qt.RightDockWidgetArea
        )
        self._create_tree()
        
        self.setWidget(self.tree)
        

        
    def _create_tree(self):
        # """创建项目树"""
        self.tree = QTreeWidget()
        self.tree.setHeaderLabel("项目结构")
        self.tree.setContextMenuPolicy(Qt.CustomContextMenu)
        self.tree.setSelectionMode(QTreeWidget.SingleSelection)
        self.tree.setAnimated(True)  # 启用展开/折叠动画
        self.tree.setSortingEnabled(True)  # 启用排序
        self.tree.sortByColumn(0, Qt.AscendingOrder)

        # 设置列宽
        self.tree.header().setSectionResizeMode(0, QHeaderView.Stretch)